{% extends "smErp/base.html" %}

{% block css_style %}
    {% load staticfiles %}
    <link href="{% static 'smErp/css/brand_info.css' %}" type="text/css" rel="stylesheet">
    <link href="{% static 'smErp/assets/dropzone/basic.min.css' %}" type="text/css" rel="stylesheet">
    <link href="{% static 'smErp/assets/dropzone/dropzone.min.css' %}" type="text/css" rel="stylesheet">

{% endblock %}


{% block content %}
    <div class="inner wrp">
        <div class="page_nav">
            <a href="{% url 'smErp:manage' %}" class="jsUrlLink" data-url="{% url 'smErp:manage' %}" target="_self">管理中心</a>
            <span class="gap">/</span>
            <a href="{% url 'smErp:brand_info' brand.id %}" class="jsUrlLink" data-url="{% url 'smErp:brand_info' brand.id %}" target="_self">品牌信息</a>
            <span class="gap">/</span>
            修改资料
        </div>
        <div class="container_box cell_layout">
            <div class="processor" id="process">
                <ol>
                    <li id="set1" class="current size1of1">
                        <div class="step_line"></div>
                        <div class="step_inner">
                            <i class="icon_step">1</i>
                            <h4>修改资料</h4>
                        </div>
                    </li>
                    <li id="set2" class="size1of2 last">
                        <div class="step_line"></div>
                        <div class="step_inner">
                            <i class="icon_step">2</i>
                            <h4>提交成功</h4>
                        </div>
                    </li>
                </ol>
            </div>
            <div class="step_panel text_padding">
                <div class="app_create_box app" id="step1">
                    <form class="form" id="form" novalidate="novalidate">
                        {% csrf_token %}
                        <div class="frm_control_group" id="js_name_group">
                            <label for="" class="frm_label">品牌名称</label>
                            <div class="frm_controls">
                                <span class="frm_input_box">
                                    <input name="name_zh" id="name_zh" class="frm_input" type="text" value="{{ brand.name_zh }}">
                                </span>
                            </div>
                        </div>
                        <div id="name_upload" class="dynamic_box"></div>
                        <div class="frm_control_group">
                            <label for="" class="frm_label">英文名称<em class="tips">(选填)</em></label>
                            <div class="frm_controls">
                                <span class="frm_input_box">
                                    <input name="name_en" id="name_en" class="frm_input" type="text" value="{{ brand.name_en }}">
                                </span>
                            </div>
                        </div>
                        <div class="frm_control_group textarea">
                            <label for="" class="frm_label">描述信息</label>
                            <div class="frm_controls">
                                <span class="frm_textarea_box">
                                    <textarea name="description" id="description" class="frm_textarea" maxlength="800">{{ brand.description }}</textarea>
                                </span>
                                <p class="frm_tips">最多800字</p>
                            </div>
                        </div>
                        <div class="frm_control_group ">
                            <label for="" class="frm_label">商标LOGO</label>
                            <div class="frm_controls">
                                <div class="frm_controls">
                                    <div class="upload_wrp">
                                        <div class="upload_box has_demo">
                                            <p class="upload_tips">
                                                请上传品牌LOGO图片
                                                <br>
                                                512*512像素，大小不超过500KB。
                                            </p>
                                            <button type="button" class="layui-btn" id="logo-img" style="background-color: #44b549;">
                                                <i class="layui-icon">&#xe67c;</i>上传图片
                                            </button>
                                            <span class="upload_area webuploader-container"></span>
                                            <input name="logo" id="logo" value="" type="hidden">
                                            <p class="upload_preview size108" id="fileView-logo" style="display: block;">
                                                <img id="brand-logo-view" src="{{ brand.logo }}">
                                            </p>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="frm_control_group ">
                            <label for="" class="frm_label">商标证书</label>
                            <div class="frm_controls">
                                <div class="frm_controls">
                                    <div class="upload_wrp">
                                        <div class="upload_box has_demo">
                                            <p class="upload_tips">
                                                请上传品牌商标证书图片
                                                <br>
                                                842*595像素，大小不超过500KB。
                                            </p>
                                            <button type="button" class="layui-btn" id="license-img" style="background-color: #44b549;">
                                                <i class="layui-icon">&#xe67c;</i>上传图片
                                            </button>
                                            <span class="upload_area webuploader-container"></span>
                                            <input name="license_img" id="license_img" value="" type="hidden">
                                            <p class="upload_preview size108" id="fileView-license" style="display: block;">
                                                <img id="brand-license-view" src="{{ brand.license_img }}">
                                            </p>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="tool_bar border with_form">
                            <a href="javascript:void(0);" class="btn btn_primary jsSendBt" id="brandBtn">提交</a>
                        </div>
                    </form>
{#                    <form action="/file-upload" class="dropzone" id="my-awesome-dropzone"></form>#}
                </div>

                <div class="app_create_box result" id="step2" style="display:none">
                    <div class="page_msg simple default">
                        <div class="inner group">
                            <span class="msg_icon_wrp">
                                <i class="icon_msg success"></i>
                            </span>
                            <div class="msg_content">
                                <h4>您的应用已成功提交审核，预计在7天内完成审核</h4>
                                <p>
                                    审核通过后，你才可以进行产品申请
                                </p>
                                <p class="spacing">
                                    <a href="{% url 'smErp:manage' %}" data-url="{% url 'smErp:manage' %}" target="_self" class="btn btn_primary jsUrlLink">查看管理中心</a>
                                </p>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
{% endblock %}

{% block footscript %}
    <script src="{% static 'smErp/assets/dropzone/dropzone.min.js' %}"></script>
    <script>

        // 存储上传的图片
        var upload_imgs = {} ;
        var id = 1;
        // logo图片
        var logo_dz_obj = {};
        var dropz_license_obj = {} ;
        $("#email").blur(function(){
{#           alert("hello world");#}
            var email = $("#email").val();
{#            alert(email);#}
            if(!email){
{#                alert("hellow");#}
                $("#email-msg").css("color","red");
                $("#email-msg").html("请输入邮箱地址");
                $("#email-msg").show();
            }
        });

        layui.use('upload', function(){
            var upload = layui.upload;
            //logo图片上传
            var logo_uploadInst = upload.render({
                elem: '#logo-img' //绑定元素
                ,url: "{% url 'smErp:image_upload' %}" //上传接口
                ,accept: 'images'
                ,data : {"max_size": 500, "height": 512, "width": 512}
                ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                    layer.load(); //上传loading
                }
                ,done: function(res){
                    //上传完毕回调
                    layer.closeAll('loading'); //关闭loading
                    if(res.result == 0){
                        // 上传成功，回显
                        layer.msg(res.reason);
                        $("#brand-logo-view").attr("src", res.img_url);
                        //fileview_logo.empty();
                        //fileview_logo.append('<img id="" src="' + res.img_url + '">');
                        $("#logo").val(res.img_url);

                    }else{
                        layer.msg(res.reason);
                    }
                }
                ,error: function(){
                    //请求异常回调
                    layer.closeAll('loading'); //关闭loading
                }
            });

            //证书图片上传
            var license_uploadInst = upload.render({
                elem: '#license-img' //绑定元素
                ,url: "{% url 'smErp:image_upload' %}" //上传接口
                ,accept: 'images'
                ,data : {"max_size": 500, "height": 595, "width": 842}
                ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                    layer.load(); //上传loading
                }
                ,done: function(res){
                    //上传完毕回调
                    layer.closeAll('loading'); //关闭loading
                    if(res.result == 0){
                        // 上传成功，回显
                        layer.msg(res.reason);
                        $("#brand-license-view").attr("src", res.img_url);
                        // fileview_logo.empty();
                        // fileview_logo.append('<img id="" src="' + res.img_url + '">');
                        $("#license_img").val(res.img_url);

                    }else{
                        layer.msg(res.reason);
                    }
                }
                ,error: function(){
                    //请求异常回调
                    layer.closeAll('loading'); //关闭loading
                }
            });
        });

        // 提交品牌修改信息
        $("#brandBtn").on("click", function(){
            var brand_info = $("#form").serialize();
            $.post("{% url 'smErp:brand_change' brand.id %}", brand_info,
                    function(data, status, xhr) {
                        if(status == "success") {
                            if(data.result == 0) {
                                // 提交品牌信息
                                alert(brand_info);
                                // 切换状态
                                // 切换状态
                                $("#set2").addClass("current");
                                $("#set1").removeClass("current");
                                $("#set1").addClass("complete");
                                $("#set1").children("div[class='step_inner']").children("i[class='icon_step']").html("");
                                $("#set1").children(".step_line").css("background-color", "#44b549");
                                // 改变进度 栏状态
                                $("#step1").hide();
                                $("#step2").show();
                            }else{
                                layer.msg(data.reason);
                            }
                        }else{
                            layer.msg(status);
                        }

                    },
            "json");
        });

        function upload_logo(){
            console.log("进行点击操作");
            logo_dz_obj.removeAllFiles();
            $("#dropz_logo").click();
        }

        function upload_license_img(){
            console.log("进行点击操作");
            dropz_license_obj.removeAllFiles();
            $("#dropz_license").click();
        }
    </script>
{% endblock %}




